package doudou.pojo;

import doudou.Interface.TalkService;

import java.io.Serializable;

//话痨套餐
public class TalkPackage extends ServicePackage implements TalkService, Serializable {
    public TalkPackage() {
        super("话痨套餐", 58, 500, 0, 30);
    }

    public void showInfo() {
        super.showInfo();
    }

    public int call(int minCount, MobileCard card) {
        int time = card.getRealTalkTime();
        int useTime;
        double spend;
        if (time >= minCount) {
            useTime = minCount;
            card.setRealTalkTime(time - minCount);
        } else {
            int overTime = minCount - time;
            spend = overTime * 0.2;
            double newMoney = card.getMoney() - spend;
            if (newMoney >= 0) {
                useTime = minCount;
                card.setRealTalkTime(0);
                card.setMoney(newMoney);
                card.setConsumAmount(card.getConsumAmount() + spend);
            } else {
                int extraTime = (int) (card.getMoney() / 0.2);
                useTime = time + extraTime;
                card.setRealTalkTime(0);
                card.setMoney(0);
                card.setConsumAmount(card.getConsumAmount() + (extraTime*0.2));
                try {
                    throw new Exception("您已通话" + useTime + "分钟，您的余额不足，请充值后使用");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        return useTime;
    }
}